<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>蓝奏云在线解析</title>
    <link rel="stylesheet" href="https://ku.oioweb.cn/LayUI/layui/css/layui.css">
    <script src="https://ku.oioweb.cn/LayUI/layui/layui.all.js"></script>
    <script src="https://ku.oioweb.cn/clipboard.js/2.0.6/clipboard.min.js"></script>
</head>
<body>
<div style="padding: 5px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">蓝奏云在线解析</div>
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-card">
                        <ul class="layui-tab-title" style="text-align: center">
                            <li class="layui-this">聚合解析</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">

                                <form class="layui-form layui-form-pane" action="">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">蓝奏云链接</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="url" autocomplete="off" placeholder="请输入链接"
                                                   class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item" pane="">
                                        <label class="layui-form-label">是否有密码</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="switch" lay-filter="encrypt" lay-skin="switch"
                                                   lay-text="有|无">
                                        </div>

                                    </div>
                                    <div class="layui-hide layui-progres">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">蓝奏云密码</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="pwd" autocomplete="off" placeholder="请输入密码"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                    <button type="submit" lay-submit lay-filter="*" class="layui-btn layui-btn-fluid">
                                        解析
                                    </button>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">在线用户解析记录</div>
                <div class="layui-card-body">
                    <table id="demo" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.$(function () {
        layui.use(['form', 'table'], function () {
            var form = layui.form, table = layui.table;
            form.render();
            table.render({
                elem: '#demo'
                , url: 'https://code.oioweb.cn/lanzou/msg.php'
                , size: "sm"
                , even: true
                , cols: [[
                    {field: 'url', title: '蓝奏云链接', align: "center"}
                    , {field: 'ip', title: 'IP', align: "center"}
                    , {field: 'terminal', title: '设备', align: "center"}
                    , {field: 'time', title: '时间', align: "center"}
                ]]
            });
            form.on('switch(encrypt)', function (data) {
                if (data.elem.checked) {
                    layui.$('.layui-progres').removeClass('layui-hide');
                } else {
                    layui.$('.layui-progres').addClass('layui-hide');
                }
            });
            form.on('submit(*)', function (data) {
                if (data.field.url === "") {
                    layer.msg("请输入链接再解析");
                    return false;
                }
                if (data.field.switch === "on") {
                    if (data.field.pwd === "") {
                        layer.msg("请输入密码");
                        return false;
                    }
                    if (data.field.pwd.length > 6) {
                        layer.msg("密码不符合规则");
                        return false;
                    }
                }
                if (data.field.url.indexOf("lanzous.com") === -1) {
                    layer.msg("这不是蓝奏云链接");
                    return false;
                }
                layui.$.ajax({
                    type: "POST",
                    url: "https://code.oioweb.cn/lanzou/api.php",
                    data: data.field,
                    dataType: "JSON",
                    beforeSend: function () {
                        layer.load();
                    }, success: function (data) {
                        layer.closeAll('loading');
                        if (data.code === 1) {
                            layer.msg(data.msg);
                            layer.alert(data.url, {
                                btn: ['下载', '复制'],
                                success: function (layero) {
                                    var btn = layero.find('.layui-layer-btn');
                                    btn.find('.layui-layer-btn0').attr({
                                        href: data.url
                                        , target: '_blank'
                                    });
                                }
                            });
                            var clipboard = new ClipboardJS('.layui-layer-btn1', {
                                text: function () {
                                    return data.url;
                                }
                            });
                            clipboard.on('success', function (e) {
                                layer.msg("复制成功");
                                clipboard.destroy();
                            });
                        } else {
                            layer.msg(data.msg);
                        }
                    }, error: function () {
                        layer.closeAll('loading');
                        layer.msg("服务器错误");
                    }
                })
                return false;
            });
        });
    })
</script>
</body>
</html>